package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_15_伤害吸血;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

/**
 * @ClassName Affix_29_伤害治疗靠属性
 * @Author jingtao-zheng
 * @Date 2022/8/29 16:34
 * @Version 1.0
 **/
@SkillType(Type = AffixFactory.SkillTypeEnum.吸血靠减血)
public class Affix_29_吸血靠减血 extends Skill {
    private int get治疗比例() {
        return getParam(0);
    }

    private int get减血比例() {
        return getParam(1);
    }

    public Affix_29_吸血靠减血(Fighter actor, skill skilldata, int probability, int[] params) {
        super(actor, skilldata, probability, params);
    }

    private RecordStreamGroup steamGroup;

    @Override
    public RecordStreamGroup record() {
        steamGroup = getRecord().stream(new RecordStreamGroup());
        steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
        return steamGroup;
    }

    //2022.5.26 James 被群攻武将攻击时，需要按照平均伤害进行计算
    @Override
    public boolean exec(Fighter actor, Fighter target) {
        long 总伤害 = getAffixAction().总伤害();

        int targetNumber = getAffixAction().get目标们Fighter().size();
        long 治疗量 = 0;
        if (targetNumber > 0) {
            long 血量损失万分值 = VALUE_比率分母 - actor.get血量万分值();
            int 减血比例 = get减血比例();
            long 触发治疗比例次数 = 1;
            if (血量损失万分值 != 0) {
                触发治疗比例次数 = 血量损失万分值 / 减血比例 + 1;
            }
            治疗量 = (总伤害 / targetNumber) * (get治疗比例() * 触发治疗比例次数) / VALUE_比率分母;
        }

        actor.set治疗(治疗量);

        // 流脚本
        steamGroup.add(new RecordStream_15_伤害吸血(actor, 治疗量)).record();

        // 统计
        getRecord().get统计().getFighter(actor.getFighterPosition()).addCUR(治疗量);
        Battle.battleLogger(6, "伤害治疗：" + actor.getName() + "目标数量：" + targetNumber + "总伤害：" + 总伤害 + "吸血比例：" + get治疗比例() + "治疗量：" + 治疗量);
        return true;
    }
}